if(paging==null) var paging = {};

paging.recordsPerPage = 50;
paging.totalNumberPage = 10;
paging.totalRecords = 0;
paging.ID = "";
paging.parentId = "";
paging.parentName = "";

paging.limitPage = function (pageCurrent, pageSet) {
    var link = "";
    var previous = "";
    var j = 0;
  
    if (this.totalRecords > this.recordsPerPage) {

        if (pageSet == 0) pageSet = 1;
        j = this.totalRecords / this.recordsPerPage; 	
        if ((this.totalRecords % this.recordsPerPage) > 0) j = j + 1;      
        if (j == 0) j = 1;

        // Thuc hien neu tong so trang it hon so trang gioi han (pagesLimit)
        if (j <= this.totalNumberPage) {

            if (j > 0) {
                for (var i = 1; i <= j; i++) {
                    if (i == pageCurrent) {
                        link += "<b>" + i + "</b>" + "&nbsp;";
                    } else {                            
                        link +=  "<a onclick=\"gotoPage("+i+","+pageSet+")\" href=\"#\" class=\"Paging_Link\">" + i + "</a>&nbsp;";
                    }	
                }
            } else {
               link = "";
            }

        } else {

            var rows, k;
            if ((j - this.totalNumberPage * pageSet) > 0) {
                rows = this.totalNumberPage * pageSet;
            } else {
                rows = j;
            }
            
            k = this.totalNumberPage * (pageSet - 1) + 1;
            if (k < rows) {
                for(var i = k; i <= rows; i++) {
                    if (i == pageCurrent) {
                        link +=  "<b>" + i + "</b>" + "&nbsp;";
                    } else {                         
                        link += "<a id=\"" + i + "\" onclick=\"gotoPage("+i+","+pageSet+")\" href=\"#\" class=\"Paging_Link\">" + i + "</a>&nbsp;";
                    }
                }
            } else {
                link = "";
            }

            //Bien luu trang
            var bse;
            //Bien luu nhom trang
            var bas;
            
            if ((j - this.totalNumberPage * pageSet) > 1) {                
                bse = pageSet * this.totalNumberPage + 1;
                bas = pageSet + 1;                    
                link += "&nbsp;&nbsp;<a onclick=\"gotoPage("+bse+","+bas+")\" href=\"#\" class=\"Paging_Link\">>></a>";
            }
            
            if (pageSet > 1) {
                bse = this.totalNumberPage * (pageSet - 1);
                bas = pageSet-1;                   
                previous = "<a onclick=\"gotoPage("+bse+","+bas+")\" href=\"#\" class=\"Paging_Link\"><<<a>&nbsp;&nbsp;";
            }
            
            if (previous != "") {
                link = previous + link;
            }
        }
    }
    if (link!="")   
        return "Trang " + link;
    else
        return "";
}


